//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
#include "Customers.h"
#include "GlassesFirms.h"
#include "StockDlg.h"
#include "Invoices.h"
#include "InvoiceReportDlg.h"
#include "Shipments.h"
#include "ShipmentReportDlg.h"
#include "Providers.h"
#include "FrameProviders.h"
#include "PaymentTypes.h"
#include "LoginDlg.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;

//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mnuCustomersClick(TObject *Sender)
{
   TfrmCustomers * frmCustomers;

   frmCustomers = new TfrmCustomers( this, dbsMain);

   try
   {
      frmCustomers->ShowModal();
   }
   __finally
   {
      delete frmCustomers;
   }
}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::mnuGlassesFirmsClick(TObject *Sender)
{
   TfrmGlassesFirms * frmGlassesFirms;

   frmGlassesFirms = new TfrmGlassesFirms( this, dbsMain);

   try
   {
      frmGlassesFirms->ShowModal();
   }
   __finally
   {
      delete frmGlassesFirms;
   }
}
//---------------------------------------------------------------------------







void __fastcall TfrmMain::mnuStockClick(TObject *Sender)
{
   TfrmStockDlg * frmStockDlg;

   frmStockDlg = new TfrmStockDlg( this, dbsMain);

   try
   {
      frmStockDlg->ShowModal();
   }
   __finally
   {
      delete frmStockDlg;                  
   }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::mnuInvoicesClick(TObject *Sender)
{
   TfrmInvoices * frmInvoices;

   frmInvoices = new TfrmInvoices( this, dbsMain);

   try
   {
      frmInvoices->ShowModal();
   }
   __finally
   {
      delete frmInvoices;
   }
}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::mnuInvoiceReportClick(TObject *Sender)
{
   TfrmInvoiceReportDlg * frmInvoiceReportDlg;

   frmInvoiceReportDlg = new TfrmInvoiceReportDlg( this, dbsMain);

   try
   {
      frmInvoiceReportDlg->ShowModal();
   }
   __finally
   {
      delete frmInvoiceReportDlg;
   }//try-finally
}
//---------------------------------------------------------------------------



void __fastcall TfrmMain::mnuShipmentsClick(TObject *Sender)
{
   TfrmShipments * frmShipments;

   frmShipments = new TfrmShipments( this, dbsMain);

   try
   {
      frmShipments->ShowModal();
   }
   __finally
   {
      delete frmShipments;
   }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::mnuShipmentsReportClick(TObject *Sender)
{
   TfrmShipmentReportDlg * frmShipmentReportDlg;

   frmShipmentReportDlg = new TfrmShipmentReportDlg( this, dbsMain);

   try
   {
      frmShipmentReportDlg->ShowModal();
   }
   __finally
   {
      delete frmShipmentReportDlg;
   }//try-finally
}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::mnuProvidersClick(TObject *Sender)
{
   TfrmProviders * frmProviders;

   frmProviders = new TfrmProviders( this, dbsMain);

   try
   {
      frmProviders->ShowModal();
   }
   __finally
   {
      delete frmProviders;
   }//try-finally
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::mnuFrameProvidersClick(TObject *Sender)
{
   TfrmFrameProviders * frmFrameProviders;

   frmFrameProviders = new TfrmFrameProviders( this, dbsMain);

   try
   {
      frmFrameProviders->ShowModal();
   }
   __finally
   {
      delete frmFrameProviders;
   }//try-finally
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::mnuPaymentTypesClick(TObject *Sender)
{
   TfrmPaymentTypes * frmPaymentTypes;

   frmPaymentTypes = new TfrmPaymentTypes( this, dbsMain);

   try
   {
      frmPaymentTypes->ShowModal();
   }
   __finally
   {
      delete frmPaymentTypes;
   }//try-finally
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::FormDestroy(TObject *Sender)
{
   if (user != NULL)
     delete user;
}
//---------------------------------------------------------------------------


void TfrmMain::showMenus()
{
   mnuTables->Visible = (user->type == ADMIN || user->type == SELLER);
   mnuCustomers->Visible = (user->type == ADMIN || user->type == SELLER);
   mnuGlassesFirms->Visible = (user->type == ADMIN);
   mnuReports->Visible = (user->type == ADMIN);
   mnuStock->Visible = (user->type == ADMIN);
   mnuInvoices->Visible = (user->type == ADMIN || user->type == SELLER);
   mnuInvoiceReport->Visible = (user->type == ADMIN);
   mnuShipments->Visible = (user->type == ADMIN);
   mnuShipmentsReport->Visible = (user->type == ADMIN);
   mnuProviders->Visible = (user->type == ADMIN);
   mnuFrameProviders->Visible = (user->type == ADMIN);
   mnuPaymentTypes->Visible = (user->type == ADMIN);
}

void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
   user = NULL;

   TfrmLoginDlg * frmLoginDlg;

   frmLoginDlg = new TfrmLoginDlg(this, dbsMain);

   try
   {
      if (frmLoginDlg->ShowModal() != mrOk)
         Application->Terminate();
      else
      {
         user = frmLoginDlg->user;
         showMenus();
      }
   }
   __finally
   {
      delete frmLoginDlg;
   }
}
//---------------------------------------------------------------------------

